package com.example.makerspace.controller.proxy;


import com.example.makerspace.domain.AgencyProductRelationshipsDO;
import com.example.makerspace.domain.DemandDO;
import com.example.makerspace.dto.*;
import com.example.makerspace.service.ProxyModuleService;
import com.example.makerspace.utils.FileUtils;
import com.sun.java.browser.net.ProxyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/api/proxy")
@Api(tags = "代理模块")
public class ProxyController {

    @Resource
    private ProxyModuleService proxyModuleService;


    private  static  String AdvancedAchievements="/home/ubuntu/java_project/static/demand/附件1：先进技术成果申请表.docx";


    private  static  String devAdvancedAchievements="/static/demand/document/产品授权模板.docx";


    private  static  String testAdvancedAchievements="/java_project/static/demand/平台认证授权书+(1) (3).docx";

    @ApiOperation(value="获取可代理公司列表接口",notes ="获取可代理公司列表接口说明")
    @GetMapping("/getProxyFirm")
    public Result getProxyFirm(HttpServletRequest request){
        return  proxyModuleService.getProxyFirm(request);
    }



    @ApiOperation(value="获取代理产品接口",notes ="获取代理公司接口说明")
    @PostMapping("/getProxyProduct")
    public Result getProxyProduct(@RequestBody PageRequest pageRequest){
        return  proxyModuleService.getProxyProduct(pageRequest);
    }

    @ApiOperation(value="修改代理状态接口-后台",notes ="修改代理状态接口说明-后台")
    @GetMapping("/updateProxy")
    public Result updateProxy(@RequestParam("id") Integer id, @RequestParam("op") String op){
        return  proxyModuleService.updateProxy(id,op);
    }


    @ApiOperation(value="一键上架产品接口",notes ="一键上架产品接口说明")
    @GetMapping("/addListProducts")
    public Result addListProducts(@RequestBody List<DemandDTO> demandDTOList){
        return  proxyModuleService.addListProducts(demandDTOList);
    }
    @ApiOperation(value="下载附件接口",notes ="下载附件接口说明")
    @GetMapping("/download")
    public void download(HttpServletResponse response, @RequestParam("filePath") String filePath) {
        FileUtils.downloadFile(response,filePath);
    }


    @ApiOperation(value="联系公司接口",notes ="联系公司接口说明")
    @GetMapping("/contactFirm")
    public Result contactFirm(@RequestParam("entName")String entName) {
        return  proxyModuleService.contactFirm(entName);
    }

    @ApiOperation(value="暂存存储接口",notes ="暂存存储接口说明")
    @GetMapping("/stageProduct")
    public Result stageProduct(@ModelAttribute StagingProductDTO StagingProductDTO){
        return  proxyModuleService.stageProduct(StagingProductDTO);
    }

    @ApiOperation(value="获取自动保存接口",notes ="获取自动保存接口说明")
    @GetMapping("/getStageProduct")
    public Result getStageProduct(HttpServletRequest request){
        return  proxyModuleService.getStageProduct(request);
    }


    /**
     * 用户代理公司上架产品接口
     * @param demandDTO
     * @return
     */
    @ApiOperation(value="用户代理公司上架产品接口",notes ="用户代理公司上架产品接口说明")
    @PostMapping("/userAgent")
    public   Result   userAgent(@ModelAttribute DemandDTO demandDTO){
        return  proxyModuleService.userAgent(demandDTO);
    }
    @ApiOperation(value="相关代理公司的列表接口",notes ="相关代理公司的列表接口说明")
    @GetMapping("/agentEntList")
    public   Result   agentEntList(HttpServletRequest request){
        return  proxyModuleService.agentEntList(request);
    }

    @ApiOperation(value="代理认证接口",notes ="代理认证接口说明")
    @PostMapping("/proxyAuthentication")
    public   Result   proxyAuthentication(@ModelAttribute AgencyProductRelationshipsDTO agencyProductRelationshipsDTO){
        return  proxyModuleService.proxyAuthentication(agencyProductRelationshipsDTO);
    }


    @ApiOperation(value="查看产品接口",notes ="查看产品接口说明")
    @GetMapping("/showProductDetail")
    public   Result   showProductDetail(@RequestParam("productName") String productName){
        return  proxyModuleService.showProductDetail(productName);
    }

    @ApiOperation(value="下载代理授权书模块接口",notes ="下载代理授权书模块接口说明")
    @GetMapping("/downloadProxy")
    public   void    downloadProxy(HttpServletResponse response){
        FileUtils.downloadFile3(response,testAdvancedAchievements);
    }

    @ApiOperation(value="取消代理接口",notes ="取消代理接口说明")
    @GetMapping("/cancelProxy")
    public   Result    cancelProxy(@RequestParam("id") Integer id){
        return  proxyModuleService.cancelProxy(id);
    }


}
